import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../routes/xin_he_routes.dart';
import '../../../utils/xh_styles.dart';
import '../../../utils/xin_he_UI_constancs.dart';
import '../../../utils/xin_he_image.dart';
import '../../home/model/xin_he_goods_item_detail_entity.dart';
import '../xin_he_goods_payment/xin_he_payment_methods_model.dart';
import 'xin_he_instant_pay_logic.dart';
///立即购买-》立即支付
class XinHeInstantPayPage extends StatelessWidget {
  XinHeInstantPayPage({Key? key,
    required this.totalPrice, required this.count, required this.zoneType, required this.order, required this.scene
  }) : super(key: key);
  // final XinHeGoodsItemDetailEntity dataModel;
  final double totalPrice;
  final int count;
  final int zoneType;
  final Map order;
  final PayScene scene;///支付场景





  @override
  Widget build(BuildContext context) {
    final logic = Get.put(XinHeInstantPayLogic());
    logic.orderMap = order;
    logic.payScene.value = scene;
    final state = Get.find<XinHeInstantPayLogic>().state;
    logic.getRealPayList(zoneType);
    return Obx(() =>  Container(
      height: 600+Get.mediaQuery.padding.bottom,
      width: Get.width,
      color: Colors.white,
      child: Column(

        children: [
          ///关闭
          Row(children: [
            Text('  '),
            Spacer(),
            GestureDetector(
              onTap: (){
                Get.back();
              },
              child: Container(
                  padding: EdgeInsets.all(8),
                  margin: const EdgeInsets.only(right: 7),
                  child: const XinHeAssetImage('assets/images/mine/sheet_close.png',width: 10,height: 10,)),
            ),
          ],),

          RichText(
              text: TextSpan(children: [
                ///￥
                TextSpan(
                  text: '￥',
                  style: TextStyle(
                    color: XinHeColor('#E84128'),
                    fontSize: 19,
                    fontWeight: FontWeight.w500,
                  ),
                ),

                ///
                TextSpan(
                  text: totalPrice.toStringAsFixed(2)??'0',
                  style: TextStyle(
                    color: XinHeColor('#E84128'),
                    fontSize: 26,
                    fontWeight: FontWeight.w500,
                  ),
                ),

              ]
              )),

          ///购买方式
          Container(
              margin: const EdgeInsets.symmetric(horizontal: 15).copyWith(top: 15),
              height: 40+logic.realPayList.length*50,
              decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(10)),
              child:Column(children: [
                Container(
                    height:40,
                    alignment: Alignment.centerLeft,
                    padding:const EdgeInsets.symmetric(horizontal: 15),
                    child: Text('支付方式',style: TextStyle(color: XinHeColor('#222222'),fontSize: 14,fontWeight: FontWeight.w500),)
                ),
                ListView.builder(
                    padding: EdgeInsets.zero,
                    physics: const NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    itemCount:logic.realPayList.length,
                    itemBuilder: (ctx,index){
                      XinHePaymentMethodModel model = logic.realPayList[index];
                      return Container(
                        height: 50,
                        child: Row(children: [
                          const SizedBox(width: 15,),
                          XinHeAssetImage('assets/images/cart/${model.icon}.png',width:17.5,height:17.5),
                          const SizedBox(width: 5,),
                          Text(model.title,style: TextStyle(color: XinHeColor('#222222'),fontSize: 13),),
                          Spacer(),
                          ///选择
                          GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: (){

                              if(!model.selected){
                                model.selected = !model.selected;
                              }
                              logic.realPayList[index] = model;
                              logic.selectedIndex.value = index;

                              for(int i =0;i<logic.realPayList.length;i++){
                                if(i!=index){
                                  XinHePaymentMethodModel model = logic.realPayList[i];
                                  model.selected = false;
                                }
                              }
                            },
                            child: Padding(
                              padding: const EdgeInsets.only(left: 15,right: 15,top: 5,bottom: 5),
                              child: XinHeAssetImage( model.selected?'assets/images/cart/cart_selected.png' :'assets/images/cart/cart_unselected.png',width:18 ,height: 18,),
                            ),
                          ),
                        ],),
                      );
                    })
              ],)
          ),

         Spacer(),
          Container(
            margin:   EdgeInsets.only(left: 15,right: 15,bottom: Get.mediaQuery.padding.bottom+25),
            height: 44,
            width: double.infinity,
            decoration: BoxDecoration(
                gradient: LinearGradient(colors: [XinHeColor('#F89A30'),XinHeColor('#E84128')]),

                color:XinHeColor('#30E9E9'),borderRadius: const BorderRadius.all(Radius.circular(22))),
            child: OutlinedButton(

              onPressed: (){

                if(zoneType == 5) {
                  logic.requestTreeOrder();
                }else {
                  logic.requestPayOrder();

                }

              },
              child:  const Text (
                "立即购买",
                style: TextStyle (fontSize: 16,color:  Colors.white, fontWeight: FontWeight.bold) ,
                strutStyle: StrutStyle(
                  fontSize: 16,
                  leading: 0,
                  height: 1.1,
                  // 1.1更居中
                  forceStrutHeight: true, // 关键属性 强制改为文字高度
                ),
              ),
            ),)



        ],



      ),
    ));
  }
}
